var roleDialog = new Dialog({
			showdiv : "roleDialog",
			title : "选择角色列表",
			x : 500,
			y : 500
		});
rootDialog.childDialog = roleDialog;
function initSelectRoles(id, type) {
	roleDialog.showdivWidth=500;
	roleDialog.showdivHeight=500;
	roleDialog.title="选择角色列表";
	openDialog(roleDialog,'' ,function() {
		
		var chakantablediv = roleDialog.contentdiv.appendChild(document.createElement("div"));
		var chakantable =  chakantablediv.appendChild(document.createElement("table"));
		chakantable.className = "table";
		
		var chakanthead = document.createElement("<thead>");
		chakanthead.setAttribute('id', 'theadzone');
		chakantable.appendChild(chakanthead);
		var chakantr = document.createElement("<tr>");
		chakantr.setAttribute("id", "tou");
		chakanthead.appendChild(chakantr);
		var chakanth1 = document.createElement("<td>");
		chakantr.appendChild(chakanth1);

		var chakanth2 = document.createElement("<td>");
		chakantr.appendChild(chakanth2);

		var chakanth3 = document.createElement("<td>");
		chakantr.appendChild(chakanth3);
		
		var chakanth4 = document.createElement("<td>");
		chakantr.appendChild(chakanth4);
		
		chakanth1.innerHTML = "<b>角色名</b>";
		chakanth2.innerHTML = "<b>角色描述</b>";
		chakanth3.innerHTML = "<b>角色等级</b>";
		chakanth4.innerHTML = "<b>全选/反选<input type='checkbox' name='quanfan' value='' onclick='ioCheckbox(\"rolecheckbox\")'></b>";

		var chakantbody = document.createElement("tbody");
		chakantbody.setAttribute('id', 'selectRoleslistZone_data');
		chakantable.appendChild(chakantbody);
		var chakantfoot = document.createElement("div");
		chakantfoot.setAttribute('id', 'selectRoleslistZone_bar');
		 roleDialog.contentdiv.appendChild(chakantfoot);
		selectRoles = {
			navigationsize : 10,
			paramname : 'selectRoles',
			page : 1,
			funcname : 'Role.findAllRolePageIsUse()',
			cellfuncs : selectRolesCellfuncs,
			pagesize : 10,
			count : 'getCountIsUse()',
			idname : 'selectRoleslistZone'
		};
		if (type=="user") {
			selectRoles.funcname="Role.findAllRolePageIsUseByUser('"+id+"',)";
			selectRoles.count="getCountIsUseBySUser('"+id+"',)";
			selectRoles.useruuid = id;
			selectRoles.exefunc = function () {
				User.findRoleidByUserUUID(selectRoles.useruuid, function(data) {
							for (var i = 0; i < data.length; i++) {
								$setV('rolecheckbox', data[i].roleid);
							}
						});
			};
			
		} else if (type=="dept") {
			if(id.split(":")[1]){
				selectRoles.funcname="Role.findAllRolePageIsUseByDept('"+id.split(":")[1]+"',)";
				selectRoles.count="getCountIsUseByDept('"+id.split(":")[1]+"',)";
			}else{
				selectRoles.funcname="Role.findAllRolePageIsUse()";
				selectRoles.count="getCountIsUse()";
			}
			selectRoles.deptid = id.split(":")[0];
			selectRoles.exefunc = function () {
				Dept.findRoleidByDeptid(selectRoles.deptid, function(data) {
							for (var i = 0; i < data.length; i++) {
								$setV('rolecheckbox', data[i].roleid);
							}
						});
			};
			
		}
		send(selectRoles);

		var divform = roleDialog.contentdiv.appendChild(document
				.createElement("div"));
		var submitbutton = divform
				.appendChild(document.createElement("button"));
		submitbutton.setAttribute('name', 'submitbutton');
		submitbutton.setAttribute('id', 'submitbutton');
		submitbutton.setAttribute('value', '应用');
		submitbutton.innerHTML="应用";
		submitbutton.onclick = function() {
			var selectv = $getV('rolecheckbox').split(";");
			var selectnv = $ngetV('rolecheckbox').split(";");
			if (type == "user") {
				User.addRoles(selectRoles.useruuid, selectv, selectnv,
						function(data) {
							if (data == 1) {
								alert('为人员添加角色成功');
							} else {
								alert('为人员添加角色失败');
							}
							closeDialog(roleDialog);
						});
			} else if (type == "dept") {
				Dept.addRoles(selectRoles.deptid, selectv, selectnv, function(
								data) {
							if (data == 1) {
								alert('为组织机构添加角色成功');
							} else {
								alert('为组织机构添加角色失败');
							}
							closeDialog(roleDialog);
						});
			}
		};

	});
}
var selectRoles = {
			navigationsize : 10,
			paramname : 'selectRoles',
			page : 1,
			funcname : 'Role.findAllRolePageIsUse()',
			cellfuncs : selectRolesCellfuncs,
			pagesize : 10,
			count : 'getCountIsUse()',
			idname : 'selectRoleslistZone'
		};
var selectRolesCellfuncs = [function(data) {
			return data.rolename;
		}, function(data) {
			return data.roletext;
		}, function(data) {
			return data.rolelevel;
		}, function(data) {
			var checkbox = document.createElement('input');
			checkbox.setAttribute('type', 'checkbox');
			checkbox.setAttribute('name', 'rolecheckbox');
			checkbox.setAttribute('id', 'rolecheckbox');
			checkbox.setAttribute('value', data.roleid);
			return checkbox;
		}];